import React, { FC } from 'react'
import {QuestionParagraphPropsType,QuestionParagraphDefaultProps} from './interface.ts'
import { Typography } from 'antd'

const { Paragraph } = Typography

const Component: FC<QuestionParagraphPropsType> = (props:QuestionParagraphPropsType) =>{
    // 这里的''和 false都是默认值
    const {text = '',isCenter = false  } = {...QuestionParagraphDefaultProps,...props}
    // 换行
    // const t = text.replaceAll('\n','<br>')--这种方式不是很适合
    const textList = text.split('\n') // ['111','222','333']
    
    return <Paragraph style={{ textAlign: isCenter ? 'center' : 'start', marginBottom:'0'}}>
        {/* <span dangerouslySetInnerHTML={{ __html: t }}></span> */}
        {textList.map((t,index)=>(
            <span key={index}>
                {index > 0 && <br />}
                {t}
            </span>
        ))}
    </Paragraph>
}

export default Component